<?php

// Include shared script

require_once('shared.php');


// Read categories translation table

$translationTable = array();
$file = file('../support/categoriesTranslationTable.txt');

foreach ($file as $line) {
	if (preg_match('#([^\t]*)\t([^\t]*)\t([^\t]*)#', $line, $matches)) {
		$translationTable[$matches[1]][$matches[2]] = rtrim($matches[3]);
	}
}


// Add categoriesIds to imported records

$stmt = $db->prepare(
	'UPDATE		sherpa_importData
	SET			categoryIds = ?
	WHERE		obergruppe = ?
	AND			untergruppe = ?'
);

foreach ($translationTable as $obergruppe => $untergruppen) {
	foreach ($untergruppen as $untergruppe => $ids) {
		$stmt->execute(array(
			$ids,
			$obergruppe,
			$untergruppe
		));
	}
}